
from flask import Flask, request, jsonify
from src.model.RanadomForest.random_forest import rf_predict
app = Flask(__name__)

@app.route('/rf_predict', methods=['POST'])
def rf_predict_api():
    """随机森林模型预测接口"""
    data = request.get_json()
    if not data or "data" not in data:
        return jsonify({
            "code": 400,
            "msg": "传参错误！请传入格式：{\"data\": \"q请输入您的文本内容\"}"
        })

    pred = rf_predict(data["data"])
    return jsonify(pred)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)
